<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>报名点管理</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <link href="../../static/css/style.css" rel="stylesheet">
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../static/js/base.js"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body>

<!--主体内容-->
<div class="layui-fluid">
    <div class="layui-card content-wrap">

        <form class="layui-form layui-form-pane" action="">
            <div class="layui-row layui-form-item layui-col-space10">
                <div class="layui-col-sm5">
                    <label class="layui-form-label">报名点名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" placeholder="请输入报名点名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-sm5">

                    <!--<button class="layui-btn add_btn" data-type="reload" id="searchBtn"><i class="layui-icon layui-icon-search"></i>搜索</button>-->
                    <a class="layui-btn add_btn" data-type="reload" id="searchBtn"><i class="layui-icon layui-icon-search"></i>搜索</a>
                    <button class="layui-btn delete_btn" data-type="reloadClean"><i class="layui-icon layui-icon-delete"></i>清空</button>

                </div>
            </div>

        </form>
        <div class="layui-form-item margintop">
            <div>
                <button class="layui-btn add_btn ax-btn" id="add"><i class="layui-icon layui-icon-add-circle"></i>增加</button>
                <button class="layui-btn ax-btn change_btn" id="update"><i class="layui-icon layui-icon-edit"></i>编辑</button>
                <button class="layui-btn ax-btn delete_btn" id="delete"><i class="layui-icon layui-icon-delete"></i>删除</button>
            </div>
        </div>
        <table class="layui-hide" id="activeListTbale" lay-filter="active"></table>

    </div>
</div>
<!--主体内容-->



</body>

<script>

    var table;
    var tableIns;
    layui.use(['table', 'form', 'laydate', 'layer','element'], function () {
        table = layui.table;
        var form = layui.form,
            layer = layui.layer;

        tableIns = ax.VTable({
            elem: '#activeListTbale',
            url: schoolWebUrl+'/api/register/list',
            id: 'testReload',
            cols: [[{
                type: 'checkbox',
                fixed: 'left'
            }, {
                width:80,
                title: '序列号',
                sort: true,
                type:'numbers'
            }, {
                field: 'name',
                minWidth: 160,
                title: '报名点名称',
            }, {
                field: 'address',
                minWidth: 160,
                title: '报名点地址',
            }, {
                field: 'mobile',
                width: 160,
                title: '报名点联系人电话',
            }, {
                field: 'parentSchool',
                minWidth: 160,
                title: '报名点所属驾校',
                templet: '#stateTpl'
            }, {
                field: 'created',
                width: 160,
                title: '创建时间'
            }]],

        });

        registers
        //监听工具条
        table.on('tool(active)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {

                layer.open({
                    type: 2,
                    title: ['查看文章', 'font-size:18px;'],
                    shadeClose: true,
                    area: ['800px', '500px'],
                    offset: ['50px', '230px'],
                    content: 'active/showMdText/' + data.activeId
                });

            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    //修改
                    ax.get({
                        type: "get",
                        url: "/active/updateState/" + data.activeId,
                        async: false,  //加了这个属性，
                        error: function (request) {
                            layer.confirm("网络错误!");
                        },
                        success: function (data) {

                            if (data.code == 200) {
                                layer.msg(data.msg);
                                table.reload('testReload');
                                layer.close(index);
                            } else {
                                layer.confirm(data.msg);
                            }

                        }
                    });

                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    title: ['修改文章', 'font-size:18px;'],
                    shadeClose: true,
                    maxmin: true,
                    area: ['800px', '500px'],
                    offset: ['50px', '230px'],
                    content: 'active/updateActive/' + data.activeId
                });

            }
        });

        var $ = layui.$, registers = {

            reload: function(){
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        name: $("#name").val()
                    }
                });
            }
        };
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            registers[type] ? registers[type].call(this) : '';
        });
      /*  //监听表格复选框选择
        table.on('checkbox(active)', function (obj) {
            console.log(obj)
        });*/

        //新增报名点
        $('#add').on('click', function(){
            top.layer.open({
                title:"新增报名点",
                type: 2,
                fixed: true, //不固定
                maxmin: true,
                area: ['90%', '80%'],
                content: './school/school/registersAdd.html'
            });
        });
        //修改报名点
        $('#update').on('click', function(){
            var checkStatus = table.checkStatus('testReload'),data = checkStatus.data;
            if(data.length>1){
                layer.close(index);
                layer.alert("最多选择一条数据");
                return;
            }
            top.layer.open({
                title:"修改报名点",
                type: 2,
                fixed: true, //不固定
                maxmin: true,
                area: ['90%', '80%'],
                content: './school/school/registersEdit.html?id='+data[0].id
            });
        });

        $('#delete').on('click', function(){
            //获取选中的数据
            layer.confirm('真的删除这行数据么?', function(index){
                var checkStatus = table.checkStatus('testReload'),data = checkStatus.data;
                if(data.length>1){
                    layer.close(index);
                    layer.alert("最多选择一条数据");
                    return;
                }
                var postData={"id":data[0].id};
                ax.post({
                    type: 'POST',
                    url: schoolWebUrl+'/api/register/delete',
                    contentType: "application/x-www-form-urlencoded",
                    data: postData,
                    success: function (r) {
                        layer.close(index);
                        layer.alert(r.message);
                        reset();

                    },
                });
            });
        });

    });
//重置页面
function reset() {
        //执行重载
        table.reload('testReload', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: {
            }
    });
}

</script>
</html>